package com.icim.xmtm098.export.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.icim.core.service.IAlarmSenderService;
import com.icim.csot.exporter.tx.csotshipping.CsotShippingO;
import com.icim.util.XmlConvertUtil;
import com.icim.xmtm098.export.service.IXmtmExportShippingData098Service;

@Controller
public class XmtmShippingdata098Controller {
    @Resource
    private IXmtmExportShippingData098Service xmtmExportShippingData098Service;
    @Resource
    private IAlarmSenderService alarmSenderService;
    
    private Logger logger = LoggerFactory.getLogger(XmtmShippingdata098Controller.class);

    @ResponseBody
    @RequestMapping("exportXmtm098Shippingdata.do")
    public String exportShippingData(String userName,String key,String model,String boxId,String prdQty){

        CsotShippingO outTrx = new CsotShippingO();
       
        try {
        	logger.info("098客户数据回传开始......[userName="+userName+";key="+key+";model="+model+";boxId="+boxId+";prdQty="+prdQty+"]");
            outTrx = xmtmExportShippingData098Service.sendShippingData(userName,key,model,boxId,prdQty);
            outTrx.setRtn_code("0000000");
            outTrx.setRtn_mesg("SUCCESS");
        } catch (Exception ex) {
        	String errorMsg="098客户数据回传箱号："+boxId+"  数据回传失败\n"+"失败原因："+ex.getMessage();
        	alarmSenderService.sendAlarm1("098",errorMsg);
            outTrx.setRtn_code("9999999");
            outTrx.setRtn_mesg(ex.getMessage());
           logger.info("error: {} " ,ex);
        }
        return XmlConvertUtil.obj2Xml(outTrx, "transaction");
    }
    
    
}
